/*
 * @Author: hzm 
 * @Date: 2020-06-19 10:19:58 
 * @Last Modified by: hzm
 * @Last Modified time: 2020-06-19 13:59:04
 */

#pragma once

#include "GlobalDef.h"

struct event;
struct event_base;

namespace HeyIM {

class Event {

public:

    Event(const Event&) = delete;
    Event& operator=(const Event&) = delete;

    virtual~Event();

    //将事件附加到loop中，开始事件处理
    bool start(int delay = 0);

    void cancel();

    bool isRunning() const;

    virtual void destroy() {};


protected:

    Event(event_base* base, VoidParamHandler handler);

    virtual void init() = 0;
    

    struct event_base* m_base = nullptr;
    struct event* m_event = nullptr;

    VoidParamHandler m_handler = nullptr;

    bool m_running = false;

};

}